import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AudioModule } from './audio/audio.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RrzArticles } from './entity/rrz_articles.entity';
import { RrzArticleNodes } from './entity/rrz_article_nodes.entity';
import { CorsMiddleware } from './corsMiddleware';
import { AudioCateService } from './audio_cate/audio_cate.service';
import { AudioCateController } from './audio_cate/audio_cate.controller';

@Module({
  imports: [
    AudioModule,
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: '127.0.0.1',
      port: 3306,
      username: 'root',
      password: 'root',
      database: 'rrzcms',
      entities: [RrzArticles, RrzArticleNodes],
      synchronize: false,
    }),
  ],
  controllers: [AppController, AudioCateController],
  providers: [AppService, AudioCateService],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(CorsMiddleware).forRoutes('*');
  }
}
